//
//  LCSetFindPwdViewController.m
//  wan77h5
//
//  Created by jiukuyinyue on 2017/9/1.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LCSetFindPwdViewController.h"
#import "LCLoginTextField.h"
//#import "ViewController.h"
//#import "LCHorizontalGrideView.h"

@interface LCSetFindPwdViewController ()

@property (weak, nonatomic) IBOutlet UIButton *loginButton;

@property (weak, nonatomic) LCLoginTextField *passwordTextField;

@property (weak, nonatomic) IBOutlet UIImageView *codeImageView;

@end

@implementation LCSetFindPwdViewController
//- (void)dealloc
//{
//    // 移除当前对象监听的事件
//    [[NSNotificationCenter defaultCenter] removeObserver:self];
//}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置密码";
    self.view.backgroundColor = RGBColor(236, 236, 236);

    _loginButton.enabled = NO;//禁用
    [self setupLogin];
    [_passwordTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    
}
 

/**
 监听键盘 输入重置密码
 */
-(void)textFieldDidChange :(UITextField *)theTextField{
    if (_passwordTextField.text.length <= 16 && _passwordTextField.text.length >= 6){
        _loginButton.enabled = YES;
    }else{
        _loginButton.enabled = NO;
    }
}
#pragma mark - 初始化布局
-(void)setupLogin{
    LCLoginTextField *passwordTextField = [[LCLoginTextField alloc] initWithFrame:CGRectMake(54, 300, 211, 30)];
    passwordTextField.font = [UIFont systemFontOfSize:15];
    passwordTextField.backgroundColor = [UIColor whiteColor];
    passwordTextField.borderStyle = UITextBorderStyleNone;
    passwordTextField.layer.borderColor = RGBColor(255, 255, 255).CGColor;
    passwordTextField.layer.borderWidth = 1;
    passwordTextField.layer.cornerRadius = 5;
    passwordTextField.placeholder = @"请输入6-16位新密码";
    [passwordTextField becomeFirstResponder];
    _passwordTextField = passwordTextField;
    [self.view insertSubview:passwordTextField atIndex:0];
    
    [passwordTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(80);
        make.centerX.equalTo(self.view);
        make.left.offset(30);
        make.right.offset(-30);
        
        make.height.offset(40);
    }];
    [_codeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(passwordTextField.mas_left).offset(6);
        make.centerY.equalTo(passwordTextField.mas_centerY);
        make.width.offset(25);
        
    }];
    [_loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_passwordTextField.mas_bottom).offset(20);
        make.left.equalTo(_passwordTextField.mas_left);
        make.right.equalTo(_passwordTextField.mas_right);
        make.height.offset(35);
    }];
}
#pragma mark -  重置密码  -
- (IBAction)clickLoginButton:(UIButton *)sender {
    
    NSDictionary *inputDic = @{@"password":[NSString stringWithFormat:@"%@", _passwordTextField.text]
                            };
    [LSZRequestData initregistrationSendVerificationCode:inputDic url:SET_PASSWORD_URL :^(BOOL isOK, NSString * str, NSDictionary * dic) {
        if (isOK == YES) {
            [SVProgressHUD showSuccessWithStatus:@"设置成功!"];
            [self.navigationController popToRootViewControllerAnimated:YES];
        }else{
           [SVProgressHUD showErrorWithStatus:str];
        }
    }];
 
//    [kNetworkTool POSTFuYinWithUrlString:SET_PASSWORD_URL input:input success:^(NSDictionary *responseObject) {
//
//        if ([[NSString stringWithFormat:@"%@", responseObject[@"status"]] isEqualToString:@"1"]) {
//            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
//                [SVProgressHUD showSuccessWithStatus:responseObject[@"msg"]];
//                [self.navigationController popToRootViewControllerAnimated:YES];
//            }];
//            [[NSNotificationCenter defaultCenter] postNotificationName:LOGINSUCCESSFUL object:self userInfo:nil];
//
//
//        }else{
//            [SVProgressHUD showErrorWithStatus:responseObject[@"msg"]];
//        }
//    } failure:nil];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
@end
